import { checkActor, randomMoveInRange } from "../utils/mirUtil";
import { randomInRange } from "../utils/utls";
import { DamageChangeData } from "../全局对象/DamageManage";
import { loopMongen } from "../全局对象/FreshMon";
import { getSpecialMonManage } from "../系统功能/GlobalObjectManage";
import { BossSkillKey, BuffGroupId, CampEnum, DeBuffGroupId, IntervalBuffGroupId, MaxIntNum, MaxPercentNum, StatusBuffGroupId } from "./基础配置";
import { getStrengSkillPower } from "./强化技能";

export const customSkillSet = [
    {
        name: "BOSS召唤",
        isDirect: false, //是否指向性技能
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            if (Source.SlaveCount < 10) {
                // for(let i=0;i<Source.SlaveCount;i++)
                // {
                //     let salve:TActor=Source.GetSlave(i);
                //     randomMoveInRange(salve,Source.Map,Source.MapX,Source.MapY,4)
                // }
                loopMongen(Source.GetMap().GetMapID(), '狐月黄蛙',
                    Source.MapX, Source.MapY, 5, 2, (newSlave: TActorList) => {
                        for (let i = 0; i < newSlave.Count; i++) {
                            let item: TActor = newSlave.Actor(i);
                            item.SetMaster(Source)
                            item.SetMasterRoyaltyTick(MaxIntNum)
                            // item.SetCamp(CampEnum.Mon)
                        }
                    });

                Source.SendMessage('出来吧我的奴仆', 3)
            }
        },
        onSkillDamage: null,
    },
    {
        name: "BOSS吞噬",
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            let salve: TActorList = Source.GetSlaveList();
            let count = salve ? salve.Count : 0;
            if (count > 5) {
                Source.SendMessage('现在是你们为主人做贡献的时候了', 3)
                let item: TActor = salve.Actor(0);

                nParam1 = Math.max(nParam1, 1);
                let hp = Math.max(item.HP, 1000) * nParam1;

                Source.AddAbilityBuff(BuffGroupId.atAC, TBuffAbilityType.atAC, 6000, 10000, true)
                Source.AddAbilityBuff(BuffGroupId.atACMax, TBuffAbilityType.atACMax, 6000, 10000, true)
                Source.AddAbilityBuff(BuffGroupId.atMAC, TBuffAbilityType.atMAC, 6000, 10000, true)
                Source.AddAbilityBuff(BuffGroupId.atMacMax, TBuffAbilityType.atMacMax, 6000, 10000, true)
                Source.AddAbilityBuff(BuffGroupId.atDC, TBuffAbilityType.atDC, 6000, 2000, true)
                Source.AddAbilityBuff(BuffGroupId.atDCMax, TBuffAbilityType.atDCMax, 6000, 2000, true)
                Source.AddAbilityBuff(BuffGroupId.atMC, TBuffAbilityType.atMC, 6000, 2000, true)
                Source.AddAbilityBuff(BuffGroupId.atMCMax, TBuffAbilityType.atMCMax, 6000, 2000, true)

                Source.HP = Source.HP + hp;


                item.MakeGhost();
            }

        }
    },
    {
        name: "BOSS召唤2",
        isDirect: false, //是否指向性技能
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            if (Source.SlaveCount < 10) {
                loopMongen(Source.GetMap().GetMapID(), '奴隶',
                    Source.MapX, Source.MapY, 5, 1, (newSlave: TActorList) => {
                        for (let i = 0; i < newSlave.Count; i++) {
                            let item: TActor = newSlave.Actor(i);
                            item.SetMaster(Source)
                            item.SetMasterRoyaltyTick(MaxIntNum)
                            // item.SetCamp(CampEnum.Mon)
                        }
                    });

                Source.SendMessage('出来吧我的奴仆', 3)
            }
        },
        onSkillDamage: null,
    },
    {
        name: "BOSS大招开启",
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            // Source.SetCheck(BossSkillKey, true);
            Source.SetState(5, 7, 0);
            Source.AddStatusBuff(StatusBuffGroupId.stNone, TBuffStatusType.stNone, 5000, -1, -1);
            Source.SendMessage('尝尝大地的愤怒吧', 3)
        }
    },
    {
        name: 'BOSS大招',
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            // Source.SetCheck(BossSkillKey, false);
        },
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {
            if (ActorObject) {
                ActorObject.SetState(5, 6, 0);
                ActorObject.AddAbilityBuff(DeBuffGroupId.atMaxHP, TBuffAbilityType.atMaxHP, 10000, -6000, true);
            }
            return null;
        }

    },
    {
        name: '秒杀',
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            if (Target && !Target.IsPlayer()) {
                if (Source && Source.IsPlayer()) {
                    let player: TPlayObject = Source as TPlayObject;
                    if (player.IsAdmin) {
                        Target.Kill();
                    }
                }

            }
        }

    },
    {
        name: '清除',
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            if (Target && !Target.IsPlayer()) {
                if (Source && Source.IsPlayer()) {
                    let player: TPlayObject = Source as TPlayObject;
                    if (player.IsAdmin) {
                        player.Map.ClearMon(true, Target.Name);
                    }
                }

            }
        }

    },
    {
        name: "GM测试1",
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {
            console.log(`${ActorObject.Name}防御${ActorObject.ACMin}-${ActorObject.ACMax} 
                魔域${ActorObject.MACMin}-${ActorObject.MACMax} 
                攻击${ActorObject.DCMin}-${ActorObject.DCMax} 魔法${ActorObject.MCMin}-${ActorObject.MACMax}`)
            let time = 6000
            let value = 10000
            ActorObject.AddAbilityBuff(DeBuffGroupId.atAC, TBuffAbilityType.atAC, time, value, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atACMax, TBuffAbilityType.atACMax, time, value, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atMAC, TBuffAbilityType.atMAC, time, value, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atMacMax, TBuffAbilityType.atMacMax, time, value, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atDC, TBuffAbilityType.atDC, time, value, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atDCMax, TBuffAbilityType.atDCMax, time, value, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atMC, TBuffAbilityType.atMC, time, value, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atMCMax, TBuffAbilityType.atMCMax, time, value, true)
            // ActorObject.AddAbilityBuff(DeBuffGroupId.atMaxHP, TBuffAbilityType.atMaxHP, 5000, -5000, true)
            if (ActorObject.IsPlayer()) {
                ActorObject.SendMessage(`防御魔防降低100% 持续5秒`, 1)
            }
            return null;
        },
    },
    {
        name: "GM测试2",
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {
            console.log(`${ActorObject.Name}防御${ActorObject.ACMin}-${ActorObject.ACMax} 
                魔域${ActorObject.MACMin}-${ActorObject.MACMax} 
                攻击${ActorObject.DCMin}-${ActorObject.DCMax} 魔法${ActorObject.MCMin}-${ActorObject.MACMax}
                伤害:${Value}`)
            return null;
        },
    },
    {
        name: '心灵召唤',
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            if (checkActor(Source)) {

                for (let i = 0; i < Source.SlaveCount; i++) {
                    let slave: TActor = Source.GetSlave(i);
                    if (checkActor(slave)) {
                        randomMoveInRange(slave, Source.Map, Source.MapX, Source.MapY, 3)
                        slave.SetTargetActor(null)
                    }
                }

            }
        }

    },
    // {
    //     name:'BOSS冰咆哮',
    // },

    {
        name: 'BOSS死亡之眼',
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {
            if (checkActor(ActorObject)) {
                ActorObject.SetState(5, 2, 0);
                ActorObject.SetState(0, 30, 30);
            }
            return null;
        },

    },
    {
        name: 'BOSS冰霜群雨',
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {
            if (checkActor(ActorObject)) {
                ActorObject.SetState(5, 3, 0);
            }
            return null;
        },

    },
    {
        name: '群体施毒',
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {
            if (checkActor(ActorObject)) {
                let dc = randomInRange(ADamageSource.DCMin, ADamageSource.DCMax + 1);
                let magic: TUserMagic = ADamageSource.FindSkill("施毒术")
                let power = SkillLevel * 50;
                if (magic) {
                    power += getStrengSkillPower(magic);
                }
                let value = Math.floor((dc / 4 + 5) * (1 + power / MaxPercentNum))

                ActorObject.SetState(1, 120, 8)
                ActorObject.SetState(0, 120, value)
                getSpecialMonManage().onMonDamage(ActorObject, ADamageSource, value * 5);
            }
            return null;
        },
    },
    {
        name: "地狱塔开启",
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {

            ADamageSource.AddIntervalBuff(IntervalBuffGroupId.biNone, TBuffIntervalType.biNone, 2000, 4000,
                ActorObject.MapX, ActorObject.MapY);
            return null;
        },
    },
    {
        name: "魔法盾开启",
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {

            Source.SetState(11, 7, 0)
            GameLib.ShowEffect(Source.Map.MapID, Source.MapX, Source.MapY, 110, 7);
        },
    },
    {
        name: 'BOSS瞬移',
        onSkillExecute: (Source: TActor, Target: TActor, AMethod: string, nParam1: number, nParam2:
            number, sParam1: string, sParam2: string): void => {
            randomMoveInRange(Source, Source.Map, Source.MapX, Source.MapY, 4)
            Source.AddAbilityBuff(BuffGroupId.atAC, TBuffAbilityType.atAC, 5000, 40, false)
            Source.AddAbilityBuff(BuffGroupId.atACMax, TBuffAbilityType.atACMax, 5000, 40, false)
            Source.AddAbilityBuff(BuffGroupId.atMAC, TBuffAbilityType.atMAC, 5000, 40, false)
            Source.AddAbilityBuff(BuffGroupId.atMCMax, TBuffAbilityType.atMCMax, 5000, 40, false)
        },
    },
    {
        name: "素狐群体",
        onSkillDamage: (ActorObject: TActor, ADamageSource: TActor, Tag: number, SkillID: number,
            SkillLevel: number, Value: number, SkillName: string): Array<DamageChangeData> => {
            ActorObject.AddAbilityBuff(DeBuffGroupId.atAC, TBuffAbilityType.atAC, 5000, -10000, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atACMax, TBuffAbilityType.atACMax, 5000, -10000, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atMAC, TBuffAbilityType.atMAC, 5000, -10000, true)
            ActorObject.AddAbilityBuff(DeBuffGroupId.atMacMax, TBuffAbilityType.atMacMax, 5000, -10000, true)
            // console.log(`${ActorObject.Name}防御${ActorObject.ACMin}-${ActorObject.ACMax} 
            //     魔域${ActorObject.MACMin}-${ActorObject.MACMax} 
            //     攻击${ActorObject.DCMin}-${ActorObject.DCMax} `)
            if (ActorObject.IsPlayer()) {
                ActorObject.SendMessage(`防御魔防降低100% 持续5秒`, 1)
            }
            return null;
        },
    },
]